<template>
	<view class="address">
		<view class="addressContent">
			<view delta="1" class="addressItem"  v-for="i in address" :key="i" @click="radiochange(i)">
			<view class="ItemTitle">
				<view :class="i.status=='1'?'Active':''" v-if="i.status=='1'">
					默认
				</view>
				<view class="ItemName">
					{{i.name}}
				</view>
				<view class="ItemPhone">
					{{i.phone}}
				</view>
			</view>
			<view class="ItemAddress">
				{{i.province+i.city+i.district+i.address}}
			</view>
		</view>
		</view>
		<view class="bottomnav savebottom">
			
		<button class="button" type="default" @click="addaddress">新增地址</button>
		</view>
	</view>
</template>

<script>
	import md5 from '@/common/api/md5.js'
	import {requestUrl} from '@/common/config.js'
	export default {
		data() {
			return {
				address:[],
				access_token:''
			};
		},
		
		onShow() {
			let time = Math.round(new Date().getTime() / 1000).toString()
			let _this = this
			let Time = ['time', time].join('=')
			this.access_token=JSON.parse(uni.getStorageSync('access_token'))
			let Access_token = ['access_token', this.access_token].join('=')
			let content = ['content=pinet.FeiMao.2017'].join()
			let arr = [content, Time].sort(function(a, b) {
				a - b
			})
			let newarr = md5(arr.join('&'))
			uni.request({
				url: requestUrl+'/app/address/getAllAddress',
				method: "GET",
				data: {
					access_token: JSON.parse(uni.getStorageSync('access_token')),
					time: time,
					sign: newarr,
				},
				success: function(res) {
					_this.address=res.data.content
				}
			});
		},
		methods:{
			radiochange(id){
				uni.setStorage({
				    key: 'address_id',
				    data: JSON.stringify(id),
				    success: function () {
				    }
				});
				uni.navigateBack({
					delta:1
				})
			},
			addaddress(){
				uni.navigateTo({
					url:'/pagesA/management/addmanagement'
				})
			}
		}
	}
</script>

<style lang="less" scoped>
.address{
	height: 100%;
	display: flex;
	flex-direction: column;
	.addressContent{
		flex: 1;
		background-color: #F3F4F5;
		padding-top: 20rpx;
	}
	.addressItem{
		padding: 30rpx;
		margin-bottom: 10rpx;
		background: #fff;
		.Active{
			font-size: 24rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
			background: #DB1B22;
			border-radius: 6rpx;
			margin-right: 20rpx;
			padding: 6rpx 14rpx;
		}
		.ItemTitle{
			display: flex;
			margin-bottom: 16rpx;
			align-items: center;
			height: 34rpx;
			.ItemName{
				font-size: 32rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #111111;
			}
			.ItemPhone{
				margin-left: 22rpx;
				font-size: 26rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #111111;
			}
		}
		.ItemAddress{
			font-size: 26rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #9DA5A8;
		}
	}
	.bottomnav{
		background: #fff;
		padding: 0 20rpx;
		box-sizing: border-box;
	}
	.savebottom {
		padding-bottom: 0;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
	}
	.button{
		width: 100%;
		margin: 0 auto;
		margin: 14rpx 0;
		background: #DB1B22;
		border-radius: 36rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
	}
}
</style>
